articles

Home / DeveloperSection / Articles / Structure and Data Types of JSON

Structure and Data Types of JSON

Anonymous User 6848 08-May-2012

This article is going to explain what structure used in JSON and you will also learn different form storing data in JSON (JavaScript Object Notation).

Data Structures supported by JSON:

JSON supports two widely used (amongst programming languages) data structures.

A collection of name/value pairs:

Different programming languages support this data structure in different names. Like object, record, struct, dictionary, hash table, keyed list, or associative array.

An ordered list of values:

 In various programming languages, it is called as array, vector, list, or sequence.

Since data structure supported by JSON is also supported by most of the modern programming languages, it makes JSON a very useful data-interchange format.

Data Types in JSON:

JSON supports an array of data types. We will discuss those in detail in the following section of this page of the JSON tutorial.

Object:

An object starts and ends with '{' and '}'. Between them, a number of string value pairs can reside. String and value is separated by a ':' and if there are more than one string value pairs, they are separated by ','.

Syntax:  {string: value, ………}

Example:

{

"firstName": "Arun Kumar ",

"lastName": " Singh",

"age": 22,

"email":"xyz@domain_name.com"

}

Array:

If the JSON data describes an array and each element of that array is an object.

[ { "name": " Arun Kumar ", "email": " xyz@domain_name.com " }, { "name": "Kumar Vishu", "email": " xyz@domain_name.com " } ]


Remember that even arrays can also be nested within an object. The following shows that.

 {"name": " Arun Kumar ",

"email": “xyz@domain_name.com”,
"age": 22,
"phoneNumber":
[
{
"type": "personal",
"number": "000000000"
},
{
"type": "fax",
"number": "000-0000-0000"
}
]
}

Value:

A value can be a string, a number, an object, an Array, an Boolean value (i.e. true or false) or Null. This structure can be nested.

Syntax:

String || Number || Object ||Array || Boolean || NULL

String:

A string is a sequence of zero or more Unicode characters, enclosed by double quotes, using backslash escapes.

Number:

There are two types number in JSON; Integer and floating number.

Whitespace:

Whitespace can be placed between any pair of supported data-types.



Updated 29-Nov-2017
I am a content writter !

Leave Comment

Comments

Liked By